package com.mmall.seckill.rabbitMQ;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by megan on 2018/7/26.
 * 消息的接收者
 */
@Slf4j
@Service
public class MQReceiver {

    @Resource
    private AmqpTemplate amqpTemplate;

    /**
     * Direct 模式交换机 Exchange
     * @param message
     */
    @RabbitListener(queues = MQConfig.QUEUE)
    public void receive(String message){
        log.info("Direct 模式交换机 Exchange 接收到消息 -->  {}",message);
    }

    /**
     * topic 模式
     */
    @RabbitListener(queues = MQConfig.TOPIC_QUEUE1)
    public void receiveTopic1(String message){
        log.info("topic1 模式 接收到消息 -->  {}",message);
    }
    @RabbitListener(queues = MQConfig.TOPIC_QUEUE2)
    public void receiveTopic2(String message){
        log.info("topic2 模式 接收到消息 -->  {}",message);
    }

    /**
     * Header 模式 交换机 Exchange
     * 里面必须出现 key，value ,根据header发送消息
     */
    @RabbitListener(queues = MQConfig.HEADER_QUEUE)
    public void receiveHeader(byte[] message){
        log.info("Header 模式 交换机 Exchange 接收到消息 -->  {}",new String(message));
    }


}
